package com.shoplink.launcher;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.droidlogic.app.DisplayPositionManager;
import com.shoplink.view.PositionMoveView;

public class ScreenZoomActivity extends Activity {

	private DisplayPositionManager mDisplayPositionManager;
	private PositionMoveView positionview;
	private ImageView jia, jian;
	private TextView percent;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		setContentView(R.layout.zoom_layout);
		positionview = (PositionMoveView) findViewById(R.id.positionview);
		percent = (TextView) findViewById(R.id.percent);
		mDisplayPositionManager = new DisplayPositionManager(this);
		percent.setText(mDisplayPositionManager.getCurrentRateValue() + "%");
		jia = (ImageView) findViewById(R.id.jia);
		jian = (ImageView) findViewById(R.id.jian);
		super.onCreate(arg0);
	}

	private void updateMainScreen() {
		Log.d("tag",
				"  percent s:s" + mDisplayPositionManager.getCurrentRateValue()
						+ "%");
		// float changeW = (float) p[0]
		// * ((float)mDisplayPositionManager.getCurrentRateValue() / 100f);
		// float changeH = (float) p[1]
		// * ((float)mDisplayPositionManager.getCurrentRateValue() / 100f);
		// positionview.startZoom((int) changeW, (int) changeH);
		// moveCount = mDisplayPositionManager.getCurrentRateValue() - 100;
		// positionview.setW(p[0] + moveCount);
		// positionview.setH(p[1] + moveCount);
		// setContentView(R.layout.zoom_layout);
		percent.setText(mDisplayPositionManager.getCurrentRateValue() + "%");
	}

	@Override
	public boolean onKeyDown(int arg0, KeyEvent arg1) {
		// TODO Auto-generated method stub

		if (arg0 == KeyEvent.KEYCODE_DPAD_UP
				|| arg0 == KeyEvent.KEYCODE_DPAD_DOWN) {
			if (arg0 == KeyEvent.KEYCODE_DPAD_UP) {
				jia.setBackgroundResource(R.drawable.icon_jia);
				handler.sendEmptyMessageDelayed(101, 200);
				mDisplayPositionManager.zoomIn();
			} else {
				jian.setBackgroundResource(R.drawable.icon_jian);
				handler.sendEmptyMessageDelayed(100, 200);
				mDisplayPositionManager.zoomOut();

			}
			updateMainScreen();
		}

		return super.onKeyDown(arg0, arg1);
	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			if (msg.what == 101) {
				jia.setBackgroundResource(R.drawable.icon_jia_d);
			} else {
				jian.setBackgroundResource(R.drawable.icon_jian_d);
			}
		};
	};

	@Override
	protected void onPause() {
		mDisplayPositionManager.saveDisplayPosition();
		// TODO Auto-generated method stub
		super.onPause();
	}

}
